package Operation;

import Book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入你要删除的书籍的名字：");
        String name = input.nextLine();
        int delSize = -1;
        int i = 0;
        for (i = 0; i < bookList.getBookSize(); i++) {
            if (name.equals(bookList.getBook(i).getName())) {
                delSize = i;
                break;
            }
        }
        if (i == bookList.getBookSize()) {
            System.out.println("没有找到要删除的书籍！");
        } else {
            for (int j = delSize; j < bookList.getBookSize() - 1; j++) {
                bookList.setBook(j + 1, bookList.getBook(j));
            }
            bookList.setBook(bookList.getBookSize(), null);
            bookList.setBookSize(bookList.getBookSize() -1);
            System.out.println("删除书籍！");
        }
    }
}
